//本代码中假设表名字叫做sxa
//注册方法为手机号加密码
//账号为手机号的md5值
<?php
use RingCentral\Psr7\Response;

function handler($request, $context): Response{

    $body       = $request->getBody()->getContents();
    $data=json_decode($body,true); 
        $a="error";
        $accountid=null;
        $pdo = new_pdo();
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $pdo->beginTransaction();
        $pdo->commit();
        $stmt = $pdo->query("SELECT accountid FROM sxa
                            WHERE phonenumber= $data[phonenumber]");
        while ($row = $stmt->fetch()) {
            $accountid = $row['accountid'];
        }
        if($accountid!=null){
            $a='the phonenumber has been registered.';
        }else{
        $accountid=md5($data['phonenumber']);
        $stmt = $pdo->query("INSERT INTO `sxa`
                            (`accountid`,`phonenumber`,`password`)
                            VALUES ('$accountid','$data[phonenumber]','$data[password]');");
        $stmt = $pdo->query("SELECT accountid FROM sxa
                            WHERE phonenumber= $data[phonenumber]");
         while ($row = $stmt->fetch()) {
            $accountid = $row['accountid'];
        }
        if($accountid!=null){
            $a='success';
        }}
    return new Response(
        200,
        array(
            'custom_header1' => 'v1',
            'custom_header2' => ['v2', 'v3'],
        ),
        $a
    );
}


//自己数据库的信息
function new_pdo()
{
    $mysql_host = "xxx";
    $mysql_port = "xxx";
    $mysql_user = "xxxx";
    $mysql_password = "xxxx";
    $mysql_dbname = "xxxx";
    return new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_dbname", $mysql_user, $mysql_password);
}